import { defineStore } from 'pinia'

export const useNoteStore = defineStore('note', {
  state: () => ({
    notes: []
  }),

  actions: {
    addNote(note) {
      const id = Date.now()
      this.notes.push({ ...note, id })
      return id
    },

    updateNote(id, updatedNote) {
      const index = this.notes.findIndex((note) => note.id === id)
      if (index !== -1) {
        this.notes[index] = { ...updatedNote, id }
      }
    },

    deleteNote(id) {
      this.notes = this.notes.filter((note) => note.id !== id)
    }
  }
})
